package com.then.architecture.di;

import android.app.Application;

import com.cocosw.favor.FavorAdapter;
import com.facebook.stetho.okhttp3.StethoInterceptor;
import com.ihsanbal.logging.Level;
import com.ihsanbal.logging.LoggingInterceptor;
import com.luojilab.componentservice.GlobalEventManager;
import com.then.architecture.BuildConfig;
import com.then.architecture.Country;
import com.then.architecture.InjectorMap;
import com.umeng.socialize.UMShareAPI;

import java.util.concurrent.TimeUnit;

import javax.inject.Singleton;
import com.luojilab.componentservice.prefs.Preferences;
import dagger.Module;
import dagger.Provides;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.internal.platform.Platform;

/**
 * Created by 42524 on 2018/1/12.
 */

@Module
public class DaggerModule {


    private final Application mApplication;

    private  Preferences preferences;

    public DaggerModule(Application application) {
        mApplication = application;
    }


    @Singleton
    @Provides
    OkHttpClient okHttpClient() {
        OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(new LoggingInterceptor.Builder()
                .loggable(BuildConfig.DEBUG)
                .setLevel(Level.BASIC)
                .log(Platform.INFO)
                .request("Request")
                .response("Response")
                .addHeader("version", BuildConfig.VERSION_NAME)
                .build()).addNetworkInterceptor(new StethoInterceptor()).connectTimeout(5, TimeUnit.SECONDS).readTimeout(10, TimeUnit.SECONDS).build();
        return okHttpClient;
    }

    @Singleton
    @Provides
    HttpUrl httpUrl() {
        return new HttpUrl.Builder().scheme(BuildConfig.SCHEME).host(BuildConfig.HOST).port(BuildConfig.PORT).addEncodedPathSegments(BuildConfig.PATH).build();
    }


    @Singleton
    @Provides
    UMShareAPI shareAPI() {
        return UMShareAPI.get(mApplication);
    }

    @Singleton
    @Provides
    public Application provideApplication() {
        return this.mApplication;
    }


    @Singleton
    @Provides
    public InjectorMap provideInjectorMap() {
        return InjectorMap.getInstance();
    }

    @Singleton
    @Provides
    public Preferences providePreferences() {
        preferences=new FavorAdapter.Builder(mApplication).build().create(Preferences.class);
        return preferences;
    }

    @Singleton
    @Provides
    public Country provideCountry() {
        return new Country(mApplication);
    }


}
